package com.macro.mall.portal.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author wwj
 */
public interface ReceiptPayDetailMapper extends BaseMapper {


    @Select("select pay_order_id,count(*) c from receipt_pay_detail where mall_id=${mallId} group by pay_order_id")
    public List<ReceiptPayDetail> getReceiptPayDetail(String mallId);


    @Select("SELECT\n" +
            "        o.merchant_no AS 'merchant_no',\n" +
            "        t.channel_merchant_no AS 'channel_merchant_no',\n" +
            "        t.channel_code AS 'channel_code',\n" +
            "        o.store_id AS 'store_id',\n" +
            "        o.store_name AS 'store_name',\n" +
            "        d.pay_order_id AS 'order_no',\n" +
            "        d.id AS 'pay_order_no',\n" +
            "        NULL AS 'channel_serial_no',\n" +
            "        o.trade_type AS 'trade_mode',\n" +
            "        d.discount_amount AS 'trans_amount',\n" +
            "        0.0000 AS 'channel_fee_rate',\n" +
            "        0.00 AS 'channel_max_fee_amount',\n" +
            "        0.00 AS 'channel_min_fee_amount',\n" +
            "        o.create_time AS 'start_time',\n" +
            "        o.pay_time AS 'finish_time',\n" +
            "        o.pay_state AS 'trade_state',\n" +
            "        o.pay_type AS 'pay_type',\n" +
            "        3 AS 'trade_type',\n" +
            "        o.terminal_no AS 'terminal_no',\n" +
            "        0 AS 'proxy_flag',\n" +
            "        NULL AS 'proxy_code',\n" +
            "        concat('3-',d.id) AS 'recon_serial_no',\n" +
            "        d.discount_type AS 'discount_type'\n" +
            "        FROM\n" +
            "        receipt_pay_order o,\n" +
            "        receipt_pay_discount d,\n" +
            "        (\n" +
            "        -- 这里会出现全库全表查询\n" +
            "        SELECT DISTINCT\n" +
            "        pay_order_id,\n" +
            "        MAX(channel_merchant_no) AS 'channel_merchant_no',\n" +
            "        MAX(channel_code) AS 'channel_code'\n" +
            "        FROM\n" +
            "        receipt_pay_detail\n" +
            "        WHERE\n" +
            "        need_account = 1\n" +
            "        GROUP BY\n" +
            "        pay_order_id\n" +
            "        ) t\n" +
            "        WHERE\n" +
            "        o.id = d.pay_order_id\n" +
            "        AND o.id = t.pay_order_id\n" +
            "        AND o.pay_state = 200")
    List<ReceiptPayDetail> getJoinTest();




    @Select("SELECT\n" +
            "        o.merchant_no AS 'merchant_no',\n" +
            "        o.store_id AS 'store_id',\n" +
            "        o.store_name AS 'store_name',\n" +
            "        d.pay_order_id AS 'order_no',\n" +
            "        d.id AS 'pay_order_no',\n" +
            "        NULL AS 'channel_serial_no',\n" +
            "        o.trade_type AS 'trade_mode',\n" +
            "        d.discount_amount AS 'trans_amount',\n" +
            "        0.0000 AS 'channel_fee_rate',\n" +
            "        0.00 AS 'channel_max_fee_amount',\n" +
            "        0.00 AS 'channel_min_fee_amount',\n" +
            "        o.create_time AS 'start_time',\n" +
            "        o.pay_time AS 'finish_time',\n" +
            "        o.pay_state AS 'trade_state',\n" +
            "        o.pay_type AS 'pay_type',\n" +
            "        3 AS 'trade_type',\n" +
            "        o.terminal_no AS 'terminal_no',\n" +
            "        0 AS 'proxy_flag',\n" +
            "        NULL AS 'proxy_code',\n" +
            "        concat('3-',d.id) AS 'recon_serial_no',\n" +
            "        d.discount_type AS 'discount_type'\n" +
            "        FROM\n" +
            "        receipt_pay_order o,\n" +
            "        receipt_pay_discount d\n" +
            "        WHERE\n" +
            "        o.id = d.pay_order_id\n" +
            "        AND o.pay_state = 200")
    List<ReceiptPayDetail> getJoinTestNotIn();


    @Select("SELECT\n" +
            "        o.merchant_no AS 'merchant_no',\n" +
            "        o.store_id AS 'store_id',\n" +
            "        o.store_name AS 'store_name',\n" +
            "        d.pay_order_id AS 'order_no',\n" +
            "        d.id AS 'pay_order_no',\n" +
            "        NULL AS 'channel_serial_no',\n" +
            "        o.trade_type AS 'trade_mode',\n" +
            "        d.discount_amount AS 'trans_amount',\n" +
            "        0.0000 AS 'channel_fee_rate',\n" +
            "        0.00 AS 'channel_max_fee_amount',\n" +
            "        0.00 AS 'channel_min_fee_amount',\n" +
            "        o.create_time AS 'start_time',\n" +
            "        o.pay_time AS 'finish_time',\n" +
            "        o.pay_state AS 'trade_state',\n" +
            "        o.pay_type AS 'pay_type',\n" +
            "        3 AS 'trade_type',\n" +
            "        o.terminal_no AS 'terminal_no',\n" +
            "        0 AS 'proxy_flag',\n" +
            "        NULL AS 'proxy_code',\n" +
            "        concat('3-',d.id) AS 'recon_serial_no',\n" +
            "        d.discount_type AS 'discount_type'\n" +
            "        FROM\n" +
            "        receipt_pay_order o,\n" +
            "        receipt_pay_discount d\n" +
            "        WHERE\n" +
            "        o.id = d.pay_order_id\n" +
            "        AND o.id in (\n" +
            "        SELECT DISTINCT\n" +
            "        pay_order_id\n" +
            "        FROM\n" +
            "        receipt_pay_detail\n" +
            "        WHERE\n" +
            "        need_account = 1\n" +
            "        GROUP BY\n" +
            "        pay_order_id\n" +
            "        )\n" +
            "        AND o.pay_state = 200")
    List<ReceiptPayDetail> getJoinInTest1();
 }
